package com.vinjogames.gfx;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.PointF;

import com.vinjogames.util.VertexBuffer;

public class Number {
	//   _      _  _       _   _  _   _   _
	//  | |  |  _| _| |_| |_  |_   | |_| |_|
	//  |_|  | |_  _|   |  _| |_|  | |_|  _|
	
	private static float one[]   = new float[]{1,1,0, 1,-1,0};
	private static float two[]   = new float[]{0,1,0, 1,1,0, 1,0,0, 0,0,0, 0,-1,0, 1,-1,0};
	private static float three[] = new float[]{0,1,0, 1,1,0, 1,0,0, 0,0,0, 1,0,0, 1,-1,0, 0,-1,0};
	private static float four[]  = new float[]{0,1,0, 0,0,0, 1,0,0, 1,1,0, 1,-1,0};
	private static float five[]  = new float[]{1,1,0, 0,1,0, 0,0,0, 1,0,0, 1,-1,0, 0,-1,0};
	private static float six[]   = new float[]{1,1,0, 0,1,0, 0,0,0, 0,-1,0, 1,-1,0, 1,0,0, 0,0,0};
	private static float seven[] = new float[]{0,1,0, 1,1,0, 1,-1,0};
	private static float eight[] = new float[]{0,0,0, 0,1,0, 1,1,0, 1,-1,0, 0,-1,0, 0,0,0, 1,0,0};
	private static float nine[]  = new float[]{1,0,0, 0,0,0, 0,1,0, 1,1,0, 1,-1,0, 0,-1,0};
	private static float zero[]  = new float[]{0,1,0, 1,1,0, 1,-1,0, 0,-1,0, 0,1,0};
	
	private static float numbers[][] = new float[][]{zero,one,two,three,four,five,six,seven,eight,nine};

	private static void draw(int n, GL10 gl){
		gl.glDisable(GL10.GL_BLEND);
		gl.glDisable(GL10.GL_TEXTURE_2D);
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		gl.glFrontFace(GL10.GL_CW);
		gl.glColor4f(1.0f, 0, 0, 1.0f);
		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, VertexBuffer.getVertexBuffer(numbers[n]));
		gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, numbers[n].length / 3);
		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
		gl.glEnable(GL10.GL_BLEND);
		gl.glEnable(GL10.GL_TEXTURE_2D);
		gl.glColor4f(1, 1, 1, 1);
	}
	
	public static void drawNumber(int num, GL10 gl, PointF location, float scale){
		gl.glPushMatrix();
		gl.glLoadIdentity();
		gl.glTranslatef(location.x, location.y, Camera.Z_DISTANCE);
		gl.glScalef(scale, scale, 1);
		
		while(num > 0){
			draw(num%10, gl);
			num /= 10;
			gl.glTranslatef(-1.5f,0,0);
		}

		gl.glPopMatrix();
	}
}